package cn.xuewenbao.edu.controller;


import cn.xuewenbao.edu.entity.Comment;
import cn.xuewenbao.edu.entity.vo.CommentVo;
import cn.xuewenbao.edu.service.CommentService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.api.vo.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * <p>
 * 评论表 前端控制器
 * </p>
 *
 * @author mafayu
 * @since 2021-03-26
 */
@RestController
@RequestMapping("/edu/article/comment")
@Api(tags = "文章评论表")
@Slf4j
public class CommentController {
    @Autowired
    private CommentService commentService;

    @ApiOperation(value = "文章评论表-插入评论")
    @PostMapping
    public boolean saveComment(@RequestBody Comment comment){
        boolean result=commentService.saveComment(comment);
        return result;
    }

    @ApiOperation(value = "文章评论表-根据文章id查询评论")
    @GetMapping("/getComment/{contentId}/{columnType}")
    public List<CommentVo> getComment(@PathVariable String contentId, @PathVariable String columnType){
        List<CommentVo> list=commentService.getComment(contentId, columnType);
        return list;
    }

    //得到该作者的昨天的评论量
    @ApiOperation("得到该作者的昨天的评论量")
    @GetMapping("getLastCommentCount/{userId}")
    public Result<Map<String, Long>> getLastCommentCount(@PathVariable String userId) {
        Result<Map<String, Long>> result = commentService.getLastCommentCount(userId);
        return result;
    }

    //得到该作者的一周的评论量
    @ApiOperation("得到该作者的一周的评论量")
    @GetMapping("getWeekCommentCount/{userId}")
    public Result<Map<String, Long>> getWeekCommentCount(@PathVariable String userId) {
        Result<Map<String, Long>> result = commentService.getWeekCommentCount(userId);
        return result;
    }

    //得到该作者的一月的评论量
    @ApiOperation("得到该作者的一月的评论量")
    @GetMapping("getMonthCommentCount/{userId}")
    public Result<Map<String, Long>> getMonthCommentCount(@PathVariable String userId) {
        Result<Map<String, Long>> result = commentService.getMonthCommentCount(userId);
        return result;
    }

    //删除评论（只能作者删除）
    @ApiOperation("删除评论（只能作者删除）")
    @DeleteMapping("deleteComment/{userId}/{commentId}")
    public Result<?> deleteComment(@PathVariable String userId,
                                   @PathVariable String commentId ) {
        Result<?>  result = commentService.deleteComment(userId,commentId);
        return result;
    }

    //获取我的已评论
    @ApiOperation("获取我的评论")
    @PostMapping("getMyComment")
    public Result<?> likeList(@RequestBody Map<String, String> map) {
        String userId = map.get("userId");
        String columnType = map.get("columnType");
        Result<?> result = commentService.getMyCommentList(userId, columnType);
        return result;
    }

}

